package com.woniuxy.caradmin.controller;


import com.woniuxy.caradmin.entity.pojo.Unit;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.UnitService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author womenzu
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/unit")
public class UnitController {
    @Autowired
    private UnitService unitService;
    @ApiOperation(value = "获取往来单位信息")
    @GetMapping(value = "/selectUnitAll")
    public R selectUnitAll(){
        List<Unit> units = unitService.selectUnitAll();
        if(units!=null&&units.size()>0){
            return R.ok().code(ResultCode.SUCCESS).message(Constaint.SUCCESS).data("units",units);
        }else{
            throw new CarException(ResultCode.UNITLISTNULL,Constaint.UNITLISTNULL);
        }
    }
}

